package com.weichen.studentgameexchange.comment.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weichen.studentgameexchange.comment.entity.Comment;
import com.weichen.studentgameexchange.comment.entity.CommentAuditLog;
import com.weichen.studentgameexchange.comment.entity.vo.AddCommentVo;
import com.weichen.studentgameexchange.comment.service.ICommentService;
import com.weichen.studentgameexchange.common.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 惟尘
 * @since 2025-02-05
 */
@RestController
@RequestMapping("/comment/comment")
public class CommentController {

    @Autowired
    ICommentService commentService;

/**
 *  TODO 用户-评论
 */
    /**
     * 用户分页查询评论信息
     *
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "用户分页查询评论信息接口")
    @GetMapping("/user/page")
    public Result userPage(@RequestParam(value = "page", defaultValue = "1") Integer page,
                            @RequestParam(value = "size", defaultValue = "5") Integer size) {
        return commentService.userPage(page, size);
    }

    @Operation(summary = "用户新增评论信息")
    @PostMapping("/user/add")
    public Result userAdd(@RequestBody AddCommentVo addCommentVo){
        return commentService.userAdd(addCommentVo);
    }

    /**
     *
     * 用户删除单个评论
     *
     * @param commentId
     * @return
     */
    @Operation(summary = "用户删除单个评论接口")
    @DeleteMapping("/user/delete/{commentId}")
    public Result userDeleteOne(@PathVariable("commentId") Long commentId) {
        return commentService.userDeleteOne(commentId);
    }

    /**
     * 用户查看自己所有的评论接口
     * @param userId
     * @return
     */
    @Operation(summary = "用户查看自己所有的评论接口")
    @GetMapping ("/user/select/{userId}")
    public Result userSelect(@PathVariable("userId") Long userId){
        return commentService.userSelect(userId);
    }
/**
 *  TODO 管理员-评论管理--评论信息
 */
    /**
     * 管理员查看单个审核日志
     * @param commentId
     * @return
     */
    @Operation(summary = "管理员查看单个审核日志接口")
    @GetMapping("/admin/selectOne/{commentId}")
    public Result adminSelectOne(@PathVariable("commentId") Long commentId){
        CommentAuditLog commentAuditLog = commentService.adminSelectOne(commentId);
        return Result.success(commentAuditLog);
    }


    /**
     * 管理员分页查询评论信息
     *
     * @param keyword
     * @param page
     * @param size
     * @return
     */
    @Operation(summary = "管理员分页查询评论信息接口")
    @GetMapping("/admin/page")
    public Result adminPage(@RequestParam("keyword") String keyword,
                            @RequestParam(value = "page", defaultValue = "1") Integer page,
                            @RequestParam(value = "size", defaultValue = "5") Integer size) {
        Page<Comment> commentPage = commentService.adminPage(keyword, page, size);
        return Result.success(commentPage);
    }

    /**
     * 管理员删除单个评论
     *
     * @param commentId
     * @return
     */
    @Operation(summary = "管理员删除单个评论接口")
    @DeleteMapping("/admin/delete/{commentId}")
    public Result adminDeleteOne(@PathVariable("commentId") Long commentId) {
        commentService.adminDeleteOne(commentId);
        return Result.success();
    }

    /**
     * 管理员批量删除多个评论
     *
     * @return
     */
    @Operation(summary = "管理员批量删除多个评论接口")
    @DeleteMapping("/admin/delete/batch")
    public Result adminDeleteBatch(@RequestBody List<Long> commentIds) {
        for (Long commentId : commentIds)
            adminDeleteOne(commentId);
        return Result.success();
    }
}
